/*
     File: BuddyCell.m
 //  HelloWorld
 //
 //  Created by Martin Le C. on 5/13/09.
 //  Copyright 2009 __MyCompanyName__. All rights reserved.
 
 */

#import "BuddyCell.h"
#import "HelloWorldAppDelegate.h"

@implementation BuddyCell

@synthesize nameLabel;
@synthesize username;
@synthesize thumb;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier])
	{
		self.target = self;
		//self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
		//self.accessoryAction = @selector(onClick:);
		//[self.contentView addSubview:statusImage];
		// cell's name label
		nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
		nameLabel.backgroundColor = [UIColor clearColor];
		nameLabel.opaque = YES;
		nameLabel.textColor = [UIColor darkGrayColor];
		nameLabel.highlightedTextColor = [UIColor lightGrayColor];
		nameLabel.font = [UIFont systemFontOfSize:12];
		[self.contentView addSubview:nameLabel];
		// cell's thumb
		thumb = [[UIImageView alloc] initWithFrame:CGRectZero];
		[self.contentView addSubview:thumb];
	}
	return self;
}

// called when the accessory view (disclosure button) is touched
- (void)onClick:(id)sender
{
	//HelloWorldAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
}

- (void)layoutSubviews
{
	[super layoutSubviews];	
    CGRect contentRect = [self.contentView bounds];
	CGRect frame = CGRectMake(contentRect.origin.x + 45.0, 8.0, contentRect.size.width, 24.0);
	nameLabel.frame = frame;
	nameLabel.text = self.username;
	// layout the status image
	UIImage* image = [UIImage imageNamed:@"thumb.png"];
	frame = CGRectMake(contentRect.origin.x+ 265.0, 7, 32, 32);
	thumb.image = image;
	thumb.frame = frame;
}

- (void)dealloc
{
	[nameLabel release];
	[thumb release];
	[username release];
    [super dealloc];
}

// called when the checkmark button is touched 
- (void)checkAction:(id)sender
{
	HelloWorldAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
	NSLog(@"username:%@", username);
	[appDelegate chatView:username];
}

@end